header = """
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "linked_list.h"
#include "globals.h"

#define GPTR(c) ((generic_ptr) c)

int pop(list *l)
{
   int *n;

   delete(&l, &n);

   return *n;
}

void push(list *l, )
{

}

int main(int argc, char *argv[])
{
   list stack;
   int *temp;

   init_list(&stack);

   srand(time(NULL));

"""

footer = """
   return 0;
}
"""

commands = {
    'while' : '    delete(&stack, GPTR(temp)); append(&stack, GPTR(temp));\n    while(*temp) {\n',
    'wend'  : '    }\n',
    'pop'   : '    delete(&stack, GPTR(temp));\n'
}

def ss2c(prog):
    out = ''

    for command in prog:
      if command in commands.keys():
         out += commands[command]
      elif command.isdigit():
         out += '    int *p_i = (int *) malloc(sizeof(int));\n'
         out += '    *p_i = ' + command + ';\n'
         out += '    append(&stack, p_i);'

    return header + out + footer

import os
def comp(source, foutput):
    f = open('/tmp/sstemp.c', 'w')
    f.write(source)
    f.close()

    os.system('gcc /tmp/sstemp.c linked_list.o linked_list.h -o %s' % foutput)
